Page({

    /**
     * 页面的初始数据
     */
    data: {
        latitude: '',
        longitude: '',
        speed: '',
        accuracy: '',
        dataList: [{
            goods_id: 1,
            goods_title: '商品标题1',
            goods_img: '../image/shangjia.jpg',
            juli: '7',
            address: '新疆大公馆',
            phone: '13999999999'
        }, {
            goods_id: 2,
            goods_title: '商品标题2',
            goods_img: '../image/shangjia.jpg',
            juli: '7',
            address: '新疆大公馆',
            phone: '13999999999'
        }, {
            goods_id: 3,
            goods_title: '商品标题3',
            goods_img: '../image/shangjia.jpg',
            juli: '7',
            address: '新疆大公馆',
            phone: '13999999999'
        }, {
            goods_id: 4,
            goods_title: '商品标题4',
            goods_img: '../image/shangjia.jpg',
            juli: '7',
            address: '新疆大公馆',
            phone: '13999999999'
        }, {
            goods_id: 5,
            goods_title: '商品标题5',
            goods_img: '../image/shangjia.jpg',
            juli: '7',
            address: '新疆大公馆',
            phone: '13999999999'
        }],
        goods_img: [{
            'img': '../image/shangjia.jpg'
        },
        {
            'img': '../image/shangjia.jpg'
        },
        {
            'img': '../image/shangjia.jpg'
        },
        {
            'img': '../image/shangjia.jpg'
        },
        ],
        indicatorDots: true,
        autoplay: true,
        interval: 5000,
        duration: 1000,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.getLocation();
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    },

    getLocation: function() {
        wx.getLocation({
            type: 'gcj02', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
            success: function(res) {
                var latitude = res.latitude
                var longitude = res.longitude
                var speed = res.speed
                var accuracy = res.accuracy
                wx.request({
                    url: 'https://xjcdz.xj128.com/',
                    data: {
                        latitude: latitude,
                        longitude: longitude,
                        speed: speed,
                        accuracy: accuracy
                    },
                    method: 'post', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
                    // header: {}, // 设置请求的 header
                    // dataType:JSON,//该语句会将服务器端的数据自动转为string类型
                    success: function(res) {
                        // success
                        console.log('submit success');
                    },
                    fail: function() {
                        // fail
                        console.log('submit fail');
                    },
                    complete: function() {
                        // complete
                        console.log('submit comlete');
                    }
                })

            },
            fail: function() {
                wx.showToast({
                    title: '授权失败',
                    icon: 'success',
                    duration: 2000
                })
            }
        });
    }
})